from flask import Blueprint, render_template
from flask_login import login_required, current_user
from app.models.models import Classes, Submissions, Users

main = Blueprint('main', __name__)

@main.route('/')
def index():
    return render_template('index.html')

@main.route('/test_db_connection')
def test_db_connection():
    try:
        user = Users.query.first()
        if user:
            return "Database connection is successful."
        else:
            return "Database is connected, but no user found."
    except Exception as e:
        return f"Database connection failed: {e}"

@main.route('/dashboard')
@login_required
def dashboard():
    if current_user.role == 'admin':
        return render_template('admin/admin_dashboard.html')
    elif current_user.role == 'teacher':
        return render_template('teacher/teacher_dashboard.html', role = current_user.role)
    elif current_user.role == 'student':
        return render_template('student/student_dashboard.html', role = current_user.role)
    else:
        return render_template('index.html')
